package bysj.dao;

import bysj.domain.GraduateProjectSource;
import bysj.domain.GraduateProjectStatus;
import util.JdbcHelper;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class GraduateProjectSourceDao {
    private static GraduateProjectSourceDao graduateProjectSourceDao = new GraduateProjectSourceDao();
    private GraduateProjectSourceDao() {
    }

    public static GraduateProjectSourceDao getInstance() {
        return graduateProjectSourceDao;
    }

    public GraduateProjectSource find(Integer id, Connection connection) throws SQLException {
        GraduateProjectSource desiredGraduateProjectSource = null;
        String sql_select_id="SELECT*FROM GraduateProjectSource WHERE id=?";
        PreparedStatement pstmt = connection.prepareStatement(sql_select_id);
        pstmt.setInt(1,id);
        ResultSet resultSet=pstmt.executeQuery();
        if(resultSet.next()){
            String description=resultSet.getString("description");
            String no = resultSet.getString("no");
            String remarks = resultSet.getString("remarks");
            desiredGraduateProjectSource= new GraduateProjectSource(id,description,no,remarks);
        }
        JdbcHelper.close(resultSet,pstmt);
        return desiredGraduateProjectSource;
    }
}
